<template>
  <el-button v-bind="$attrs" size="medium" @click="executeDelete"><slot></slot></el-button>
</template>

<script >
 import http from "network/http";
 import ApiResponse from "utils/ApiResponse";
 export default {
   name: 'DeleteButton' ,
   props:{
     primaryId: null ,
     url: {
       type: String ,
       required: true ,
     },
   },
   data(){
     return {

     }
   },
   methods:{
     executeDelete(){
       this.$confirm('确认删除该记录吗？', '提示', {
         confirmButtonText: '确定',
         cancelButtonText: '取消',
         type: 'warning'
       }).then(() => {
          this.handleRequest()
       }).catch(() => {

       });
     },
     handleRequest(){
       http.delete(`${this.url}/${this.primaryId}`).then(res=>{
         ApiResponse.init(res).ok(()=>{
           this.$emit("success",res)
         }).print()

       })
     }
   }
 }
</script>


<style scoped>

</style>